package org.agile2soft.nexoma.core.entity;

import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;

import javax.persistence.CascadeType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import org.agile2soft.nexoma.expedient.entity.ExpedientTypePhase;

@Entity
@Table(name = "PROFILE", uniqueConstraints = @UniqueConstraint(columnNames = "PER_NAME"))
@SuppressWarnings({"serial"})
public class Profile implements java.io.Serializable {

    private Integer id;
    private String name;
    private boolean status;
    private boolean editable;
    private String comments;
    private Set<InternalUser> internalUsers = new HashSet<InternalUser>(0);
    private Set<ExpedientTypePhase> expedientTypePhases = new HashSet<ExpedientTypePhase>(0);
    private Set<Service> services = new HashSet<Service>(0);


    public Profile() {
    }

    public Profile(String name, boolean status, boolean editable) {
        this.name = name;
        this.status = status;
        this.editable = editable;
    }

    public Profile(String name, boolean status,
            boolean editable, String comments,
            Set<InternalUser> internalUsers,
            Set<ExpedientTypePhase> expedientTypePhases,
            Set<Service> services) {
        this.name = name;
        this.status = status;
        this.editable = editable;
        this.comments = comments;
        this.internalUsers = internalUsers;
        this.expedientTypePhases = expedientTypePhases;
        this.services = services;
    }

    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "PER_ID", unique = true, nullable = false)
    public Integer getId() {
        return this.id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @Column(name = "PER_NAME", unique = true, nullable = false, length = 30)
    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column(name = "PER_STATUS", nullable = false)
    public boolean isStatus() {
        return this.status;
    }

    public void setStatus(boolean status) {
        this.status = status;
    }

    @Column(name = "PER_EDITABLE", nullable = false)
    public boolean isEditable() {
        return this.editable;
    }

    public void setEditable(boolean editable) {
        this.editable = editable;
    }

    @Column(name = "PER_COMMENTS", length = 100)
    public String getComments() {
        return this.comments;
    }

    public void setComments(String comments) {
        this.comments = comments;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "profile")
    public Set<InternalUser> getInternalUsers() {
        return this.internalUsers;
    }

    public void setInternalUsers(Set<InternalUser> internalUser) {
        this.internalUsers = internalUser;
    }

    @ManyToMany(fetch = FetchType.LAZY,cascade=CascadeType.ALL)
    @JoinTable( name = "expedient_type_phases_profile"
              , joinColumns = { @JoinColumn(name = "PER_ID", nullable = false, updatable = false) }
              , inverseJoinColumns = { @JoinColumn(name = "FAS_ID", nullable = false, updatable = false)
                                     , @JoinColumn(name = "TEX_ID", nullable = false, updatable = false)})
    public Set<ExpedientTypePhase> getExpedientTypePhases() {
        return this.expedientTypePhases;
    }

    public void setExpedientTypePhases(
            Set<ExpedientTypePhase> expedientTypePhases) {
        this.expedientTypePhases = expedientTypePhases;
    }

    @ManyToMany(fetch=FetchType.LAZY)
    @JoinTable(name="profile_services"
              , joinColumns = { @JoinColumn(name="PER_ID",nullable=false,updatable=false) }
              , inverseJoinColumns = { @JoinColumn(name="SER_ID") } )
    public Set<Service> getServices() {
        return this.services;
    }

    public void setServices(Set<Service>services) {
        this.services=services;
    }

}
